﻿using Abp.AutoMapper;
using Abp.Runtime.Validation;
using NetCore.CustomAttributes;
using NetCore.Dtos;
using NetCore.Entities.Organizations;
using NetCore.Enums;
using NetCore.Projects.Dtos;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace NetCore.Organizations.Dtos
{
    /// <summary>
    /// 组织机构
    /// </summary>
    [AutoMap(typeof(Organization)), Description("组织机构")]
    public class OrganizationDto : BaseDto
    {
        public OrganizationDto()
        {
            Users = new List<OrganizationUserDto>();
            Childrens = new List<OrganizationDto>();
            Projects = new List<ProjectDto>();
        }
        /// <summary>
        /// 岗位用户
        /// </summary>
        [Description("岗位用户"), NotSet]
        public List<ProjectDto> Projects { get; set; }
        /// <summary>
        /// 岗位用户
        /// </summary>
        [Description("岗位用户"), NotSet]
        public List<OrganizationUserDto> Users { get; set; }
        /// <summary>
        /// 子级机构 dto使用List因为前端好使用foreach
        /// </summary>
        [Description("子级机构"), NotSet]
        public List<OrganizationDto> Childrens { get; set; }
        /// <summary>
        /// 父级机构
        /// </summary>
        [Description("父级机构")]
        public long? ParentId { get; set; }
        /// <summary>
        /// 父级机构
        /// </summary>
        [Description("父级机构")]
        public string ParentName { get; set; }
        /// <summary>
        /// 机构代码
        /// </summary>
        [Description("代码"), MaxLength(500)]
        public string Code { get; set; }
        /// <summary>
        /// 类型
        /// </summary>
        [Description("类型"), MaxLength(500)]
        public OrganizationType OrganizationType { get; set; }
        /// <summary>
        /// 节点层级
        /// </summary>
        [Description("层级")]
        public TreeNodeLevel Level { get; set; }
        public override void AddValidationErrors(CustomValidationContext context)
        {
            //if (!Phone.Validate())
            //{
            //    context.Results.Add(new ValidationResult("请输入正确的电话号码!"));
            //}
            //if (Files.Count > 20)
            //{
            //    context.Results.Add(new ValidationResult("批量上传文件最多20个"));
            //}
        }
    }
}
